package codebush.web;

import java.io.IOException;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 
 * 2008-6-24
 * 
 * @author Fution Bai Copyright 2007
 */

public class WebHelp {

	/**
	 * make a user invalid, remove all session attributes and cookies that the
	 * user has
	 */
	public static void invalidateUser(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
		session.removeAttribute("email");
		session.removeAttribute("userId");
		session.removeAttribute("userName");
		session.removeAttribute("passwordVerified");

		Cookie[] cookies = request.getCookies();
		for (int i = 0; i < cookies.length; i++) {
			cookies[i].setMaxAge(0);
			cookies[i].setPath("/");
			response.addCookie(cookies[i]);
		}
	}

	public static void sendRedirectToVerifyPassword(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws IOException {
		String queryString = request.getQueryString();
		String _con = request.getRequestURL().append("?").append(queryString).toString();
		response.sendRedirect("/codebush/support/verifyPassword?_continue=" + _con);
	}
}
